# -*- coding: UTF-8 -*-

import logging.handlers

from common.Constants import *


def get_logger(__name__):
    handler = logging.handlers.RotatingFileHandler(
        log_file_path,
        # maxBytes=1024 * 1024,
        backupCount=5,
        encoding='utf-8'
    )

    fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

    formatter = logging.Formatter(fmt)  # 实例化formatter
    handler.setFormatter(formatter)  # 为handler添加formatter

    # 再创建一个handler，用于输出到控制台
    ch = logging.StreamHandler()
    ch.setFormatter(formatter)

    logger = logging.getLogger(__name__)
    logger.addHandler(handler)  # 为logger添加handler
    logger.addHandler(ch)
    logger.setLevel(log_level)

    # logging.basicConfig(
    #     level=log_level,
    #     format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
    # )
    # logger = logging.getLogger(__name__)

    return logger